﻿using IOP.SgrA;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace VkSample113;

public class LandSystem : ComponentSystem
{
    public override void Update(TimeSpan lastStamp)
    {
        ContextManager.Foreach<LandGourp>((group) =>
        {
            Context context = ContextManager.GetContext(group.Entity);
            IRenderObject render = context.GetContextRenderObject();
            ref MVPMatrix mvp = ref context.GetMVPMatrix();
            mvp.ModelMatrix = Matrix4x4.CreateTranslation(new Vector3(0, -100f, 0));
            context.PushToRenderGroup();
        });
        ContextManager.Foreach<SeaGourp>((group) =>
        {
            Context context = ContextManager.GetContext(group.Entity);
            IRenderObject render = context.GetContextRenderObject();
            var trans = render.GetTransform();
            ref MVPMatrix mvp = ref context.GetMVPMatrix();
            mvp.ModelMatrix = Matrix4x4.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitX, -90f * MathF.PI / 180.0f)) * Matrix4x4.CreateTranslation(trans.Position);
            var a = render.GetComponents<WaveAnimation>().First();
            a.Play(lastStamp);
            context.PushToRenderGroup();
        });
        ContextManager.Foreach<SkyGourp>((group) =>
        {
            Context context = ContextManager.GetContext(group.Entity);
            IRenderObject render = context.GetContextRenderObject();
            var trans = render.GetTransform();
            ref MVPMatrix mvp = ref context.GetMVPMatrix();
            context.PushToRenderGroup();
        });
    }
}
